<template>
  <div v-loading="detailInfoShow">
    <div
      class="requestAdd"
      v-if="
        !selectionMaterialShow &&
        !requestAddShow &&
        !paymentAddShow &&
        !inorderAddShow
      "
    >
      <!-- 筛选按钮 -->
      <div class="search-button" v-if="!contactAddShow">
        <el-button
          v-if="pageType === 'check'"
          class="btn save"
          @click="handleCheckBtn2('', 3, '同意')"
          ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
          >同意</el-button
        >
        <el-button
          v-if="pageType === 'check'"
          class="btn withdraw"
          @click="handleCheckBtn2('', 4, '拒绝')"
          ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
          >拒绝</el-button
        >

        <el-button
          v-if="pageType === 'check'"
          class="btn withdraw"
          @click="handleCheckBtn2('', 6, '驳回')"
          ><el-icon class="icon" color="#fff"> <DocumentDelete /> </el-icon
          >驳回</el-button
        >
        <el-button
          v-if="pageType !== 'detail' && pageType !== 'check'"
          class="btn submit"
          @click="handleAddSave(requestFormRef, 1)"
          ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
          >提交</el-button
        >
        <el-button
          v-if="pageType !== 'detail' && pageType !== 'check'"
          class="btn save"
          @click="handleAddSave(requestFormRef, 0)"
          ><el-icon class="icon" color="#fff"> <Tickets /> </el-icon
          >存为草稿</el-button
        >
        <el-button
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal' &&
            requestForm.contractType !== 2
          "
          class="btn add"
          @click="handleAddPayment()"
          ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
          >申请付款</el-button
        >
        <el-button
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal' &&
            requestForm.contractType !== 2
          "
          class="btn add"
          @click="handleAddTicket()"
          ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
          >新增到票</el-button
        >
        <el-button
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal' &&
            requestForm.contractType !== 2
          "
          class="btn add"
          @click="handleAddInorder()"
          ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
          >新增入库</el-button
        >
        <el-button class="btn direction" @click="handleBack"
          ><el-icon class="icon" color="#fff"> <Back /> </el-icon
          >返回</el-button
        >
      </div>
      <el-collapse v-model="activeNames">
        <!-- 基础信息 -->
        <el-collapse-item
          name="1"
          v-if="!contactAddShow"
          class="transform-down"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title"
              >{{
                pageType == "detail" || pageType == "check"
                  ? ""
                  : pageType === "add"
                  ? "新增"
                  : "编辑"
              }}合同用印信息</span
            >
          </template>
          <div class="request-info">
            <el-form
                  :model="requestForm"
                  ref="requestFormRef"
                  :rules="queryRules"
                  label-width="120px"
                  v-enterToNext
                  :disabled="pageType === 'detail' || pageType === 'check'"
                >
                  <el-row>
                    <el-col :span="6">
                      <el-form-item label="合同编号：">
                        <el-input
                          disabled
                          v-model="requestForm.purchaseContractCode"
                          placeholder="自动获取"
                          clearable
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item
                        label="合同名称："
                        prop="purchaseContractName"
                      >
                        <el-input
                          v-model="requestForm.purchaseContractName"
                          placeholder="请输入"
                          clearable
                          class="search-input"
                          maxlength="50"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="申请日期：" prop="applicantDate">
                        <el-date-picker
                          v-model="requestForm.applicantDate"
                          format="YYYY/MM/DD"
                          class="search-input"
                          value-format="YYYY-MM-DD"
                          type="date"
                          placeholder="请选择"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="经办人：" prop="applicantId">
                        <el-select
                          filterable
                          v-model="requestForm.applicantId"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                          @change="handleUserChange"
                          value-key="userId"
                          placement="bottom-end"
                        >
                          <!-- <el-option
                        v-for="dict in userList"
                        :key="dict.userId"
                        :label="dict.nickName"
                        :value="dict.userId"
                      /> -->
                          <el-option disabled :value="null">
                            <div class="auto-top">
                              <span class="auto-item">人员姓名</span>
                              <span class="auto-item">联系方式</span>
                              <span class="auto-item">职位</span>
                              <span class="auto-item">部门</span>
                            </div>
                          </el-option>
                          <el-option
                            v-for="dict in userList"
                            :key="dict.userId"
                            :value="dict.userId"
                            :label="dict.nickName"
                          >
                            <div style="display: flex">
                              <div class="auto-item" :title="dict.nickName">
                                {{ dict.nickName }}
                              </div>
                              <div class="auto-item" :title="dict.phonenumber">
                                {{ dict.phonenumber ? dict.phonenumber : "--" }}
                              </div>
                              <div class="auto-item" :title="dict.postName">
                                {{ dict.postName ? dict.postName : "--" }}
                              </div>
                              <div class="auto-item" :title="dict.fullDeptName">
                                {{
                                  dict.fullDeptName ? dict.fullDeptName : "--"
                                }}
                              </div>
                            </div>
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6">
                      <el-form-item label="经办部门：">
                        <el-input
                          disabled
                          v-model="requestForm.deptName"
                          placeholder="自动获取"
                          clearable
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col :span="6">
                      <el-form-item label="合同类型：" prop="contractType">
                        <el-select
                          v-model="requestForm.contractType"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                          @change="handleType"
                        >
                          <template v-for="dict in typeList" :key="dict.value">
                            <template
                              v-if="pageType == 'add' || pageType == 'edit'"
                            >
                              <el-option
                                v-if="dict.label !== '框架协议'"
                                :label="dict.label"
                                :value="dict.value"
                              />
                            </template>
                            <template v-else>
                              <el-option
                                :label="dict.label"
                                :value="dict.value"
                              />
                            </template>
                          </template>
                        </el-select>
                      </el-form-item>
                    </el-col>

                    <el-col
                      :span="6"
                      v-if="[5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="原合同：" prop="sourceContract">
                        <el-select
                          style="width: 268px"
                          v-model="requestForm.sourceContract"
                          placeholder="请选择"
                          clearable
                          @change="handleContractSelect2"
                        >
                          <el-option disabled :value="{}">
                            <div class="auto-top">
                              <span class="auto-item">合同编号</span>
                              <span class="auto-item">合同名称</span>
                              <span class="auto-item">供应商</span>
                              <span class="auto-item">合同类型</span>
                            </div>
                          </el-option>
                          <el-option
                            v-for="dict in sourceContractList2"
                            :key="dict.purchaseContractId"
                            :value="dict.purchaseContractId"
                            :label="dict.purchaseContractName"
                          >
                            <div style="display: flex">
                              <div
                                class="auto-item"
                                :title="dict.purchaseContractCode"
                              >
                                {{ dict.purchaseContractCode }}
                              </div>
                              <div
                                class="auto-item"
                                :title="dict.purchaseContractName"
                              >
                                {{ dict.purchaseContractName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="dict.distributorName"
                              >
                                {{ dict.distributorName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="dict.contractTypeName"
                              >
                                {{ dict.contractTypeName }}
                              </div>
                            </div>
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[0, 1, 3, 4, 5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="采购类型：" prop="purchaseType">
                        <el-select
                          v-model="requestForm.purchaseType"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                        >
                          <el-option
                            v-for="dict in purchaseTypeList"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>

                    <el-col
                      :span="6"
                      v-if="
                        [0, 1, 3, 4].includes(requestForm.contractType) ||
                        [0].includes(requestForm.originType)
                      "
                    >
                      <el-form-item label="采购用途：">
                        <el-input
                          maxlength="50"
                          v-model="requestForm.purchaseUse"
                          placeholder="请输入"
                          clearable
                          class="search-input"
                        />
                      </el-form-item>
                    </el-col>

                    <el-col
                      :span="6"
                      v-if="[0, 3, 4, 5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="关联采购单：">
                        <!-- <el-select
                      v-model="requestForm.purchaseOrderId"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                      @change="handleOrderChange"
                    >
                      <el-option
                        v-for="dict in orderList"
                        :key="dict.purchaseOrderId"
                        :label="dict.purchaseOrderCode"
                        :value="dict.purchaseOrderId"
                        :disabled="dict.checkMaterialStatus==0?true:false"
                        @click="openPrompt(dict)"
                      />
                    </el-select> -->
                        <el-autocomplete
                          ref="inputRef"
                          popper-class="autoclass"
                          v-model="requestForm.purchaseOrderCode"
                          :fetch-suggestions="purchaseSearch"
                          placeholder="请选择"
                          @select="handlePurchaseSelect"
                          style="width: 268px"
                          clearable
                          placement="bottom-end"
                          @change="handlePurchaseChange"
                        >
                          <template #default="{ item }">
                            <div class="auto-top" style="display: flex">
                              <div class="auto-item">采购编号</div>
                              <div class="auto-item">采购类型</div>
                              <div class="auto-item">采购人</div>
                              <div class="auto-item">申请时间</div>
                            </div>
                            <div
                              style="display: flex"
                              :class="
                                item.checkMaterialStatus == 0
                                  ? 'disabled-bg'
                                  : ''
                              "
                            >
                              <div
                                class="auto-item"
                                :title="item.purchaseOrderCode"
                              >
                                {{ item.purchaseOrderCode }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.purchaseOrderTypeName"
                              >
                                {{ item.purchaseOrderTypeName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.applicantName"
                              >
                                {{ item.applicantName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.applicantDate"
                              >
                                {{ item.applicantDate }}
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="
                        [0, 3, 4, 5].includes(requestForm.contractType) &&
                        requestForm.purchaseOrderId
                          ? true
                          : false
                      "
                    >
                      <!--  prop="purchaseInqMaterialDetailLitsRespVos" -->
                      <el-form-item label="关联请购单：">
                        <el-select
                          style="width: 268px"
                          value-key="purchaseMaterialId"
                          multiple
                          v-model="
                            requestForm.purchaseInqMaterialDetailLitsRespVos
                          "
                          placeholder="请选择"
                          clearable
                          @change="handleRequestChange"
                          :disabled="requestForm.purchaseOrderId ? true : false"
                        >
                          <el-option disabled :value="{}">
                            <div class="auto-top">
                              <span class="auto-item">请购编号</span>
                              <span class="auto-item">物料编号</span>
                              <span class="auto-item">物料名称</span>
                              <span class="auto-item">供应商</span>
                              <span class="auto-item">购买数量</span>
                              <span class="auto-item">关联项目</span>
                            </div>
                          </el-option>
                          <el-option
                            v-for="dict in requestFilterList"
                            :key="dict.purchaseMaterialId"
                            :value="dict"
                            :label="
                              dict.purchaseApplyCode +
                              ' ' +
                              dict.materialCode +
                              ' ' +
                              dict.materialName
                            "
                          >
                            <div style="display: flex">
                              <div
                                class="auto-item"
                                :title="dict.purchaseApplyCode"
                              >
                                {{ dict.purchaseApplyCode }}
                              </div>
                              <div class="auto-item" :title="dict.materialCode">
                                {{ dict.materialCode }}
                              </div>
                              <div class="auto-item" :title="dict.materialName">
                                {{ dict.materialName }}
                              </div>
                              <div class="auto-item" :title="dict.supplierName">
                                {{ dict.supplierName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="dict.purchaseNumber"
                              >
                                {{ dict.purchaseNumber }}
                              </div>
                              <div class="auto-item" :title="dict.projectName">
                                {{ dict.projectName }}
                              </div>
                            </div>
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <!--   prop="purchaseInqMaterialDetailLitsRespVos" -->
                    <el-col
                      :span="6"
                      v-if="
                        [0, 3, 4, 5].includes(requestForm.contractType) &&
                        !requestForm.purchaseOrderId
                      "
                    >
                      <el-form-item label="关联请购单：">
                        <el-select
                          style="width: 268px"
                          value-key="purchaseMaterialId"
                          multiple
                          v-model="
                            requestForm.purchaseInqMaterialDetailLitsRespVos
                          "
                          placeholder="请选择"
                          clearable
                          @change="handleRequestChange"
                          :disabled="requestForm.purchaseOrderId ? true : false"
                        >
                          <el-option
                            disabled
                            :value="{}"
                            v-if="requestAllList.length"
                          >
                            <div class="auto-top">
                              <span class="auto-item">请购编号</span>
                              <span class="auto-item">物料编号</span>
                              <span class="auto-item">物料名称</span>
                              <span class="auto-item">供应商</span>
                              <span class="auto-item">购买数量</span>
                              <span class="auto-item">关联项目</span>
                            </div>
                          </el-option>
                          <el-option
                            v-for="dict in requestAllList"
                            :key="dict.purchaseMaterialId"
                            :value="dict"
                            :label="
                              dict.purchaseApplyCode +
                              ' ' +
                              dict.materialCode +
                              ' ' +
                              dict.materialName
                            "
                          >
                            <div style="display: flex">
                              <div
                                class="auto-item"
                                :title="dict.purchaseApplyCode"
                              >
                                {{ dict.purchaseApplyCode }}
                              </div>
                              <div class="auto-item" :title="dict.materialCode">
                                {{ dict.materialCode }}
                              </div>
                              <div class="auto-item" :title="dict.materialName">
                                {{ dict.materialName }}
                              </div>
                              <div class="auto-item" :title="dict.supplierName">
                                {{ dict.supplierName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="dict.purchaseNumber"
                              >
                                {{ dict.purchaseNumber }}
                              </div>
                              <div class="auto-item" :title="dict.projectName">
                                {{ dict.projectName }}
                              </div>
                            </div>
                          </el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[0, 3, 4, 5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="关联项目：">
                        <el-tooltip
                          class="box-item"
                          effect="dark"
                          :content="projectInfo"
                          placement="top-start"
                        >
                          <!-- :disabled="projectInfo ? false : true" -->
                          <el-select
                            value-key="projectId"
                            multiple
                            v-model="requestForm.purchaseProjectListRespVos"
                            placeholder="请选择"
                            clearable
                            disabled
                            style="width: 268px"
                            @change="handleProject"
                          >
                            <!-- :disabled="requestForm.purchaseInqMaterialDetailLitsRespVos.length>0?true:false" -->
                            <el-option
                              v-for="dict in projectList"
                              :key="dict.projectId"
                              :label="dict.projectName"
                              :value="dict"
                            />
                          </el-select>
                        </el-tooltip>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[2].includes(requestForm.contractType)"
                    >
                      <el-form-item label="原合同：" prop="sourceContractName">
                        <el-autocomplete
                          popper-class="autoclass"
                          v-model="requestForm.sourceContractName"
                          :fetch-suggestions="contractSearch"
                          placeholder="请选择原合同"
                          @select="handleContractSelect"
                          style="width: 268px"
                          clearable
                          placement="bottom-end"
                        >
                          <template #default="{ item }">
                            <div class="auto-top" style="display: flex">
                              <div class="auto-item">合同编号</div>
                              <div class="auto-item">合同名称</div>
                              <div class="auto-item">供应商</div>
                            </div>
                            <div style="display: flex; width: 380px">
                              <div
                                class="auto-item"
                                :title="item.purchaseContractCode"
                              >
                                {{ item.purchaseContractCode }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.purchaseContractName"
                              >
                                {{ item.purchaseContractName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.distributorName"
                              >
                                {{ item.distributorName }}
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[0, 1, 2,3,4, 5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="甲方单位：" prop="partyUnits">
                        <el-select
                      :placeholder="'请选择'"
                      placement="bottom-end"
                      v-model="requestForm.partyUnits"
                      clearable
                      class="search-input"
                    >
                      <el-option
                        v-for="dict in partyUnitsList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                      </el-form-item>
                    </el-col>

                    <el-col
                      :span="6"
                      v-if="false"
                    >
                      <el-form-item label="供应商：" prop="supplierName">
                        <el-autocomplete
                          popper-class="autoclass"
                          v-model="requestForm.supplierName"
                          :fetch-suggestions="querySearch"
                          placeholder="请输入"
                          @select="handleSuppliereSelect"
                          style="width: 268px"
                          placement="bottom-end"
                          clearable
                          :disabled="
                            requestForm.contractType == 2 ? true : false
                          "
                        >
                          <template #default="{ item }">
                            <div class="auto-top" style="display: flex">
                              <div class="auto-item">供应商编号</div>
                              <div class="auto-item">供应商简称</div>
                              <div class="auto-item">供应商全称</div>
                              <div class="auto-item">供应商地址</div>
                            </div>
                            <div style="display: flex; width: 500px">
                              <div class="auto-item" :title="item.supplierCode">
                                {{ item.supplierCode }}
                              </div>
                              <div
                                class="auto-item"
                                :title="item.supplierAbbreviation"
                              >
                                {{ item.supplierAbbreviation }}
                              </div>
                              <div class="auto-item" :title="item.supplierName">
                                {{ item.supplierName }}
                              </div>
                              <div
                                class="auto-item"
                                :title="`${item.provinceName}${item.cityName}${item.areaName}`"
                              >
                                {{ item.provinceName }}{{ item.cityName
                                }}{{ item.areaName }}
                              </div>
                            </div>
                          </template>
                        </el-autocomplete>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[0, 1, 2,3,4, 5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="供应商：" prop="supplierId">
                        <el-select
                          v-model="requestForm.supplierId"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                          @change="handleSupplierChange"
                        >
                          <el-option
                            v-for="dict in suppliereList"
                            :key="dict.supplierId"
                            :label="
                              dict.supplierCode +
                              ' ' +
                              dict.supplierAbbreviation +
                              ' ' +
                              dict.supplierName
                            "
                            :value="dict.supplierId"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <!-- <el-col :span="6">
                  <el-form-item label="原合同金额：">
                    <el-input
                      type="Number"
                      v-model="requestForm.contractAmount"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col> -->
                    <el-col
                      :span="6"
                      v-if="[2].includes(requestForm.contractType)"
                    >
                      <el-form-item label="解除原因：" prop="secureReason">
                        <el-select
                          v-model="requestForm.secureReason"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                        >
                          <el-option
                            v-for="dict in relieveList"
                            :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="
                        [0, 1, 2, 3, 4, 5].includes(requestForm.contractType)
                      "
                    >
                      <el-form-item
                        :label="
                          requestForm.contractType === 2 ||
                          requestForm.contractType === 6
                            ? '原合同金额：'
                            : '合同金额：'
                        "
                        prop="contractAmount"
                      >
                        <el-input
                          type="Number"
                          v-model="requestForm.contractAmount"
                          placeholder="请输入"
                          clearable
                          class="search-input"
                          @blur="handleChangePrice"
                        >
                          <template #append>元</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="变动金额：" prop="changeMoney">
                        <el-input
                          @blur="handleChangePrice"
                          type="Number"
                          v-model="requestForm.changeMoney"
                          placeholder="请输入"
                          clearable
                          class="search-input"
                        >
                          <template #append>元</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[5].includes(requestForm.contractType)"
                    >
                      <el-form-item
                        label="现合同金额："
                        prop="newContractMoney"
                      >
                        <el-input
                          disabled
                          type="Number"
                          v-model="requestForm.newContractMoney"
                          placeholder="自动计算"
                          clearable
                          class="search-input"
                        >
                          <template #append>元</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[0, 1, 2, 3,4,5].includes(requestForm.contractType)"
                    >
                      <el-form-item label="用印文件：" prop="printedDocuments">
                        <el-input
                          type="Number"
                          v-model="requestForm.printedDocuments"
                          placeholder="请输入"
                          clearable
                          class="search-input"
                          :max="99"
                        >
                          <template #append>份</template>
                        </el-input>
                      </el-form-item>
                    </el-col>
                    <el-col :span="6"  v-if="
                        [0, 1, 3, 4, 5].includes(requestForm.contractType)
                      ">
                  <el-form-item label="履约保证金：" >
                    <el-input
                      type="Number"
                      v-model="requestForm.refund"
                      placeholder="请输入"
                      clearable
                      maxlength="21"
                      class="search-input"
                    >
                      <template #append>%</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                
               
                <el-col :span="6"  v-if="
                        [0, 1, 2, 3, 4, 5].includes(requestForm.contractType)
                      ">
                  <el-form-item label="应归档份数：" prop="pigeonholeNumber">
                    <el-input
                      v-model="requestForm.pigeonholeNumber"
                      type="Number"
                      placeholder="请输入"
                      clearable
                      :max="99"
                      class="search-input"
                    >
                      <template #append>份</template></el-input
                    >
                  </el-form-item>
                </el-col>
                    <el-col
                      :span="6"
                      v-if="false"
                    >
                      <el-form-item label="关联框架协议：" prop="frameworkId">
                        <el-select
                          v-model="requestForm.frameworkId"
                          placeholder="请选择"
                          clearable
                          class="search-input"
                          @change="handleFrameChange"
                        >
                          <el-option
                            v-for="dict in frameList"
                            :key="dict.purchaseContractId"
                            :label="
                              dict.purchaseContractCode +
                              ' ' +
                              dict.purchaseContractName +
                              ' ' +
                              dict.distributorName
                            "
                            :value="dict.purchaseContractId"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[ 1].includes(requestForm.contractType)"
                    >
                      <el-form-item label="起始日期：">
                        <el-date-picker
                          v-model="requestForm.startDate"
                          format="YYYY/MM/DD"
                          class="search-input"
                          value-format="YYYY-MM-DD"
                          type="date"
                          placeholder="请选择"
                          @change="handleServeTime(1)"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[ 1].includes(requestForm.contractType)"
                    >
                      <el-form-item label="截止日期：">
                        <el-date-picker
                          v-model="requestForm.endDate"
                          format="YYYY/MM/DD"
                          class="search-input"
                          value-format="YYYY-MM-DD"
                          type="date"
                          placeholder="请选择"
                          @change="handleServeTime(2)"
                        />
                      </el-form-item>
                    </el-col>
                    <el-col
                      :span="6"
                      v-if="[ 1].includes(requestForm.contractType)"
                    >
                      <el-form-item label="服务时长(天)：">
                        <el-input
                          disabled
                          v-model="requestForm.serviceTime"
                          placeholder="自动获取"
                          clearable
                          class="search-input"
                        >
                        </el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="合同备注：">
                        <el-input
                          maxlength="200"
                          style="width: 100%"
                          v-model="requestForm.remarks"
                          type="textarea"
                          placeholder="请输入"
                          rows="4"
                        ></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col
                      :span="6"
                      v-if="[0, 1, 2, 5, 6].includes(requestForm.contractType)"
                    >
                      <el-form-item label="合同附件：" prop="suppFileInfoVos">
                        <Upload
                          :fileList="requestForm.suppFileInfoVos"
                          :isFull="true"
                          :limit="10"
                          :showButton="true"
                          @success="(result) => uploadSuccess(result)"
                          @deleteFile="(result) => uploadRemove(result)"
                          :isCanDelete="pageType == 'detail' ? false : true"
                          :disabled="pageType == 'detail'"
                        />
                        <!-- accept=".jpg,.png" -->
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
          </div>
        </el-collapse-item>
        <!-- 添加物料 -->
        <el-collapse-item
          name="2"
          style="position: relative"
          v-if="contactAddShow"
          class="transform-up"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">添加物料</span>
            <div class="nofixed-search-button button-position" v-if="false">
              <el-button class="btn save" @click.stop="handleHand"
                ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
                >手动添加</el-button
              >
              <el-button class="btn submit" @click.stop="handleMaterial"
                ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
                >选择物料</el-button
              >
            </div>
          </template>
          <div class="request-info">
            <el-form
              :model="contactForm"
              ref="contactFormRef"
              :rules="queryContactRules"
              label-width="100px"
              v-enterToNext
            >
              <el-row>
                <el-col :span="6">
                  <el-form-item label="物料编号：">
                    <el-input
                      v-model="contactForm.materialCode"
                      placeholder="自动生成"
                      clearable
                      class="search-input"
                      disabled=""
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="物料名称：" prop="materialName">
                    <el-input
                      :disabled="contactForm.materialCode !== ''"
                      ref="refInput"
                      v-model="contactForm.materialName"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="出厂型号：" prop="factoryCode">
                    <el-input
                      :disabled="contactForm.materialCode !== ''"
                      v-model="contactForm.factoryCode"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="技术参数：" prop="technologyParameter">
                    <el-input
                      :disabled="contactForm.materialCode !== ''"
                      v-model="contactForm.technologyParameter"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="0">
                <el-col :span="6">
                  <el-form-item label="单位：" prop="materialUnit">
                    <el-select
                      :disabled="contactForm.materialCode !== ''"
                      v-model="contactForm.materialUnit"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                      @change="handleUnitChange"
                    >
                      <el-option
                        v-for="dict in unitList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="采购数量：" prop="purchaseNumber">
                    <!-- disabled -->
                    <el-input
                      type="Number"
                      v-model="contactForm.purchaseNumber"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    />
                  </el-form-item>
                </el-col>

                <!-- </el-row>
              <el-row> -->
                <el-col :span="6">
                  <el-form-item label="采购单价：" prop="purchasePrice">
                    <el-input
                      type="Number"
                      v-model="contactForm.purchasePrice"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="税率：" prop="taxRate">
                    <!-- <el-input
                      type="Number"
                      v-model="contactForm.taxRate"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    >
                      <template #append>%</template>
                    </el-input> -->
                    <el-select
                      v-model="contactForm.taxRate"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                      @change="handlePrice"
                    >
                      <el-option
                        v-for="dict in taxRateList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="税额：">
                    <el-input
                      pattern="/^\d+(\.\d{1,2})?$/"
                      disabled
                      type="Number"
                      v-model="contactForm.taxAmount"
                      placeholder="单价、自动计算"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="不含税金额：">
                    <el-input
                      disabled
                      type="Number"
                      v-model="contactForm.noTaxAmount"
                      placeholder="单价、自动计算"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="总金额：">
                    <el-input
                      disabled
                      v-model="contactForm.allPrice"
                      placeholder="自动获取"
                      clearable
                      class="search-input"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="运费：" prop="freight">
                    <el-input
                      type="Number"
                      v-model="contactForm.freight"
                      placeholder="请输入"
                      clearable
                      class="search-input"
                      @blur="handlePrice"
                    >
                      <template #append>元</template>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="发票类型：" prop="invoiceType">
                    <el-select
                      v-model="contactForm.invoiceType"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                      @change="handleTypeChange"
                    >
                      <el-option
                        v-for="dict in invoiceTypeList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="到货周期：" prop="deliveryCycle">
                    <el-input
                      v-model="contactForm.deliveryCycle"
                      placeholder="如：一周内。方便采购了解优先级，以保障供应时效"
                      clearable
                      class="search-input"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="requestForm.contractType == 4">
                  <el-form-item label="渠道：">
                    <el-select
                      v-model="contactForm.channel"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                      :disabled="requestForm.purchaseOrderId ? true : false"
                      @change="changeChannel"
                    >
                      <el-option
                        v-for="dict in channelList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6" v-if="false">
                  <el-form-item label="供应商：">
                    <el-select
                      filterable
                      v-model="requestForm.supplierId"
                      placeholder="请选择"
                      clearable
                      class="search-input"
                    >
                      <template v-if="suppliereList.length">
                        <el-option disabled :value="{}">
                          <div class="auto-top">
                            <span class="auto-item">供应商编号</span>
                            <span class="auto-item">供应商简称</span>
                            <span class="auto-item">供应商全称</span>
                            <span class="auto-item">供应商地址</span>
                          </div>
                        </el-option>
                        <el-option
                          v-for="dict in suppliereList"
                          :key="dict.supplierId"
                          :value="dict.supplierId"
                          :label="
                            dict.supplierCode +
                            ' ' +
                            dict.supplierAbbreviation +
                            ' ' +
                            dict.supplierName
                          "
                        >
                          <div style="display: flex">
                            <div class="auto-item" :title="dict.supplierCode">
                              {{ dict.supplierCode }}
                            </div>
                            <div
                              class="auto-item"
                              :title="dict.supplierAbbreviation"
                            >
                              {{ dict.supplierAbbreviation }}
                            </div>
                            <div class="auto-item" :title="dict.supplierName">
                              {{ dict.supplierName }}
                            </div>
                            <div
                              class="auto-item"
                              :title="
                                dict.provinceName
                                  ? `${dict.provinceName}${dict.cityName}${dict.areaName}`
                                  : ''
                              "
                            >
                              {{ dict.provinceName }}{{ dict.cityName
                              }}{{ dict.areaName }}
                            </div>
                          </div>
                        </el-option>
                      </template>

                      <template v-else>
                        <el-option
                          v-for="dict in []"
                          :key="dict.supplierId"
                          :label="dict.supplierId"
                          :value="dict.supplierId"
                        />
                      </template>
                    </el-select>
                    <!-- <el-autocomplete
                      popper-class="autoclass"
                      v-model="contactForm.supplierName"
                      :fetch-suggestions="querySearch"
                      placeholder="请输入"
                      @input="handleSuppliereInput(1)"
                      @select="handleSuppliereSelect($event, 1)"
                      style="width: 268px"
                      clearable
                      placement="bottom-end"
                      :disabled="requestForm.purchaseOrderId ? true : false"
                    >
                      <template #default="{ item }">
                        <div class="auto-top" style="display: flex">
                          <div class="auto-item">供应商编号</div>
                          <div class="auto-item">供应商简称</div>
                          <div class="auto-item">供应商全称</div>
                          <div class="auto-item">供应商地址</div>
                        </div>
                        <div style="display: flex; width: 500px">
                          <div class="auto-item" :title="item.supplierCode">
                            {{ item.supplierCode }}
                          </div>
                          <div
                            class="auto-item"
                            :title="item.supplierAbbreviation"
                          >
                            {{ item.supplierAbbreviation }}
                          </div>
                          <div class="auto-item" :title="item.supplierName">
                            {{ item.supplierName }}
                          </div>
                          <div
                            class="auto-item"
                            :title="`${item.provinceName}${item.cityName}${item.areaName}`"
                          >
                            {{ item.provinceName }}{{ item.cityName
                            }}{{ item.areaName }}
                          </div>
                        </div>
                      </template>
                    </el-autocomplete> -->
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </el-collapse-item>
        <!-- 框架协议列表 -->
        <el-collapse-item
          name="5"
          style="position: relative; margin: 20px 0"
          :class="!contactAddShow ? 'transform-down' : ''"
          v-if="false"
        >
          <!-- v-if="requestForm.contractType === 3 && !contactAddShow" -->
          <!--  && requestForm.frameworkId -->
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">框架协议列表</span>
          </template>
          <div class="contact-info">
            <!-- 表格数据 -->
            <el-table
              :data="requestForm.purchaseConMaterialByIdRespVos"
              border
              :height="'100%'"
              :header-cell-style="{ 'text-align': 'center' }"
            >
              <el-table-column
                type="index"
                label="序号"
                width="70"
                align="center"
              />
              <el-table-column
                label="物料编号"
                prop="materialCode"
                :show-overflow-tooltip="true"
                min-width="160"
              >
                <template #default="{ row }">
                  <span>{{ row.materialCode ? row.materialCode : "--" }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="物料名称"
                prop="materialName"
                :show-overflow-tooltip="true"
                min-width="160"
              />

              <el-table-column
                label="出厂型号"
                prop="factoryCode"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="技术参数"
                prop="technologyParameter"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="单位"
                prop="materialUnitName"
                :show-overflow-tooltip="true"
                min-width="100"
              />
              <el-table-column
                label="采购数量"
                prop="purchaseNumber"
                :show-overflow-tooltip="true"
                min-width="100"
              />

              <el-table-column
                label="已用数量"
                prop="usedQuantity"
                :show-overflow-tooltip="true"
                min-width="100"
              >
                <template #default="{ row }">
                  <span>{{ row.usedQuantity ? row.usedQuantity : 0 }}</span>
                </template>
              </el-table-column>

              <el-table-column
                label="剩余数量"
                prop="remainingQuantity"
                :show-overflow-tooltip="true"
                min-width="100"
              >
                <template #default="{ row }">
                  <span>{{
                    row.remainingQuantity ? row.remainingQuantity : 0
                  }}</span>
                </template>
              </el-table-column>

              <el-table-column
                label="本次使用数量"
                prop="quantity"
                :show-overflow-tooltip="true"
                width="300"
              >
                <template #default="{ row, $index }">
                  <el-input
                    v-if="pageType === 'add' || pageType === 'edit'"
                    type="Number"
                    v-model="row.quantity"
                    placeholder="请输入"
                    clearable
                    @blur="handleQuantity(row, $index)"
                  />
                  <!-- class="search-input" -->
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-collapse-item>
        <!-- 物料列表 -->
        <el-collapse-item
          name="3"
          style="position: relative"
          :class="!contactAddShow ? 'transform-down' : ''"
          v-if="requestForm.contractType !== 2"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">物料列表</span>
            <div
              v-if="
                pageType !== 'detail' && pageType !== 'check' && !contactAddShow
              "
              class="nofixed-search-button button-position"
            >
              <!-- v-if="!requestForm.purchaseOrderId" -->
              <el-button class="btn submit" @click.stop="handleMaterial"
                ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
                >选择物料</el-button
              >
              <!-- <el-button v-else class="btn submit" @click.stop="handleMaterial"
                ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
                >选择物料</el-button
              > -->
            </div>
            <div
              class="nofixed-search-button button-position"
              v-else
              v-if="pageType !== 'detail' && pageType !== 'check'"
            >
              <el-button
                class="btn add"
                @click.stop="handleContactAdd(contactFormRef)"
                ><el-icon class="icon" color="#fff"> <Plus /> </el-icon
                >{{ operateType == "edit" ? "保存" : "添加" }}</el-button
              >
              <el-button class="btn direction" @click.stop="handleRequestBack"
                ><el-icon class="icon" color="#fff"> <ArrowUp /> </el-icon
                >关闭</el-button
              >
            </div>
          </template>
          <div class="contact-info">
            <!-- 表格数据 -->
            <el-table
              :data="requestForm.purchaseContractMaterialRespVos"
              border
              :height="
                pageType === 'detail' || pageType === 'check'
                  ? '100%'
                  : contactAddShow
                  ? '320px'
                  : '280px'
              "
              :header-cell-style="{ 'text-align': 'center' }"
              show-summary
              sum-text="合计"
              :summary-method="getSummaries"
            >
              <!-- 操作模式 -->
              <el-table-column
                label="操作"
                align="center"
                :show-overflow-tooltip="true"
                width="100px"
                v-if="pageType !== 'detail' && pageType !== 'check'"
              >
                <template #default="{ row, $index }">
                  <div class="table-operate">
                    <img
                      src="@/assets/icons/images/edit.png"
                      class="table-icon"
                      title="编辑"
                      @click="handleOperate('edit', row, $index)"
                    />
                    <img
                      src="@/assets/icons/images/delete.png"
                      class="table-icon"
                      title="删除"
                      @click="handleOperate('delete', row, $index)"
                    />
                  </div> </template
              ></el-table-column>
              <!-- <el-table-column
                label="序号"
                prop="materialCode"
                :show-overflow-tooltip="true"
                min-width="160"
              /> -->
              <el-table-column
                label="物料编号"
                prop="materialCode"
                :show-overflow-tooltip="true"
                min-width="160"
              >
                <template #default="{ row }">
                  <span>{{ row.materialCode ? row.materialCode : "--" }}</span>
                </template>
              </el-table-column>
              <el-table-column
                label="物料名称"
                prop="materialName"
                :show-overflow-tooltip="true"
                min-width="160"
              >
                <template #header>
                  <span style="color: red">*</span>
                  <span>物料名称</span>
                </template>
              </el-table-column>
              <el-table-column
                label="出厂型号"
                prop="factoryCode"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>出厂型号</span>
                </template>
              </el-table-column>
              <el-table-column
                label="技术参数"
                prop="technologyParameter"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>技术参数</span>
                </template>
              </el-table-column>
              <el-table-column
                label="单位"
                prop="materialUnitName"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>单位</span>
                </template>
              </el-table-column>
              <el-table-column
                label="采购数量"
                prop="purchaseNumber"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>采购数量</span>
                </template>
              </el-table-column>

              <el-table-column
                label="采购单价（元）"
                prop="purchasePrice"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>采购单价（元）</span>
                </template>
              </el-table-column>
              <el-table-column
                label="税率（%）"
                prop="taxRate"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>税率（%）</span>
                </template>
              </el-table-column>
              <el-table-column
                label="税额（元）"
                prop="taxAmount"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>税额（元）</span>
                </template>
              </el-table-column>
              <el-table-column
                label="不含税金额（元）"
                prop="noTaxAmount"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>不含税金额（元）</span>
                </template>
              </el-table-column>

              <el-table-column
                label="运费（元）"
                prop="freight"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>运费（元）</span>
                </template>
              </el-table-column>
              <el-table-column
                label="总金额（元）"
                prop="allPrice"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>总金额（元）</span>
                </template>
              </el-table-column>
              <el-table-column
                label="发票类型"
                prop="invoiceTypeName"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>发票类型</span>
                </template>
              </el-table-column>
              <el-table-column
                label="到货周期"
                prop="deliveryCycle"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>到货周期</span>
                </template>
              </el-table-column>
              <!-- <el-table-column
                label="渠道"
                prop="channelName"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>渠道</span>
                </template>
              </el-table-column> -->
              <el-table-column
                label="供应商"
                prop="supplierName"
                :show-overflow-tooltip="true"
                min-width="160"
                ><template #header>
                  <span style="color: red">*</span>
                  <span>供应商</span>
                </template>
              </el-table-column>
              <!-- <el-table-column
                label="生产厂商"
                prop="manufactureName"
                :show-overflow-tooltip="true"
                min-width="160"
              /> -->
            </el-table>
          </div>
        </el-collapse-item>
        <!-- 付款记录 -->
        <el-collapse-item
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal'
          "
          name="4"
          style="position: relative; margin-top: 20px"
          :class="!contactAddShow ? 'transform-down' : ''"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">付款记录</span>
          </template>
          <div class="contact-info">
            <!-- 表格数据 -->
            <el-table
              :data="paymentList"
              border
              :height="'100%'"
              :header-cell-style="{ 'text-align': 'center' }"
              show-summary
              sum-text="合计"
              :summary-method="getSummariesPaymentList"
            >
              <!-- 操作模式 -->
              <el-table-column
                label="操作"
                align="center"
                :show-overflow-tooltip="true"
                width="100px"
              >
                <template #default="{ row, $index }">
                  <div class="table-operate">
                    <img
                      src="@/assets/icons/images/edit.png"
                      class="table-icon"
                      title="编辑"
                      @click="handlePayOperate('edit', row, $index)"
                      v-if="[0, 5, 6].includes(row.paymentCheckStatus)"
                    />
                    <img
                      src="@/assets/icons/images/delete.png"
                      class="table-icon"
                      title="删除"
                      @click="handlePayOperate('delete', row, $index)"
                      v-if="[0, 5].includes(row.paymentCheckStatus)"
                    />
                  </div> </template
              ></el-table-column>
              <el-table-column
                label="付款编号"
                prop="paymentApplyCode"
                :show-overflow-tooltip="true"
                min-width="120"
              />
              <el-table-column
                label="申请日期"
                prop="applicantDate"
                :show-overflow-tooltip="true"
                width="120"
              />
              <el-table-column
                label="申请人"
                prop="applicantName"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="申请部门"
                prop="deptName"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="付款方式"
                prop="paymentMethodName"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="用款用途"
                prop="useFunds"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="户名"
                prop="accountName"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="账号"
                prop="accountCode"
                :show-overflow-tooltip="true"
                min-width="80"
              />
              <el-table-column
                label="申请付款金额（元）"
                prop="paymentAmount"
                :show-overflow-tooltip="true"
                width="160"
              />
              <el-table-column
                label="实付金额（元）"
                prop="actualAmount"
                :show-overflow-tooltip="true"
                width="140"
              />
              <el-table-column
                label="审核状态"
                prop="paymentCheckStatusName"
                :show-overflow-tooltip="true"
                min-width="80"
              />
            </el-table>
          </div>
        </el-collapse-item>
        <!-- 到票记录 -->
        <el-collapse-item
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal'
          "
          name="5"
          style="position: relative; margin-top: 20px"
          :class="!contactAddShow ? 'transform-down' : ''"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">到票记录</span>
          </template>
          <div class="contact-info">
            <!-- 表格数据 -->
            <el-table
              :data="ticketList"
              border
              :height="'100%'"
              :header-cell-style="{ 'text-align': 'center' }"
              show-summary
              sum-text="合计"
              :summary-method="getSummariesTicket"
            >
              <!-- 操作模式 -->
              <el-table-column
                label="操作"
                align="center"
                :show-overflow-tooltip="true"
                width="100px"
              >
                <template #default="{ row, $index }">
                  <div class="table-operate">
                    <img
                      src="@/assets/icons/images/edit.png"
                      class="table-icon"
                      title="编辑"
                      @click="handleTicketOperate('edit', row, $index)"
                    />
                    <img
                      src="@/assets/icons/images/delete.png"
                      class="table-icon"
                      title="删除"
                      @click="handleTicketOperate('delete', row, $index)"
                    />
                  </div> </template
              ></el-table-column>
              <el-table-column
                label="到票编号"
                prop="arrivalInvoiceCode"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="到票日期"
                prop="arrivalInvoiceDate"
                :show-overflow-tooltip="true"
                min-width="160"
              />

              <el-table-column
                label="经办人"
                prop="userName"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="经办部门"
                prop="deptName"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="开票方"
                prop="supplierName"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="发票类型"
                prop="invoiceTypeName"
                :show-overflow-tooltip="true"
                min-width="160"
              />

              <el-table-column
                label="发票号"
                prop="invoiceCode"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="到票金额（元）"
                prop="invoiceAmount"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="备注"
                prop="remarks"
                :show-overflow-tooltip="true"
                min-width="160"
              />
              <el-table-column
                label="关联入库单"
                prop="purchaseConWarehouseInfoRespVos"
                :show-overflow-tooltip="true"
                min-width="160"
              >
                <template #default="{ row, $index }">
                  <span
                    v-for="(item, index) in row.purchaseConWarehouseInfoRespVos"
                  >
                    <span v-if="item">{{ item.warehousingApplyCode }}</span>
                    <span
                      v-if="
                        index !== row.purchaseConWarehouseInfoRespVos.length - 1
                      "
                      >，</span
                    >
                  </span>
                </template>
              </el-table-column>

              <el-table-column
                label="附件"
                prop="suppFileInfoVos"
                :show-overflow-tooltip="true"
                min-width="160"
              >
                <template #default="{ row, $index }">
                  <span v-for="(item, index) in row.suppFileInfoVos">
                    <span>{{ item.name }}</span>
                    <span v-if="index !== row.suppFileInfoVos.length - 1"
                      >，</span
                    >
                  </span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-collapse-item>
        <!-- 入库记录 -->
        <el-collapse-item
          v-if="
            pageType === 'detail' &&
            requestForm.contractCheckStatus === 3 &&
            route.name === 'ContractSeal'
          "
          name="7"
          style="position: relative; margin-top: 20px"
          :class="!contactAddShow ? 'transform-down' : ''"
        >
          <template #title>
            <span class="circle"></span>
            <span class="collapse-title">入库记录</span>
          </template>
          <div class="contact-info">
            <!-- 表格数据 -->
            <el-table
              :data="inorderList"
              border
              :height="'100%'"
              :header-cell-style="{ 'text-align': 'center' }"
              show-summary
              sum-text="合计"
              :summary-method="getSummariesPaymentList"
            >
              <el-table-column
                label="入库编号"
                prop="warehousingApplyCode"
                :show-overflow-tooltip="true"
                min-width="150"
              />
              <el-table-column
                label="申请日期"
                prop="applicantDate"
                :show-overflow-tooltip="true"
                min-width="150"
              />
              <!--:formatter="dateFormat"-->
              <el-table-column
                label="申请人"
                prop="applicantName"
                :show-overflow-tooltip="true"
                min-width="150"
              />
              <el-table-column
                label="申请部门"
                prop="deptName"
                :show-overflow-tooltip="true"
                min-width="150"
              />
              <el-table-column
                label="入库数量"
                prop="warehousingQuantity"
                :show-overflow-tooltip="true"
                min-width="120"
              />
              <el-table-column
                label="审核状态"
                prop="warehousingCheckStatusName"
                :show-overflow-tooltip="true"
                min-width="150"
              />
            </el-table>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
    <!-- 选择物料 -->
    <SelectionMaterial
      ref="selectionMaterialRef"
      v-if="selectionMaterialShow"
      v-model:selectionMaterialShow="selectionMaterialShow"
      :RequestChooseList="requestForm.purchaseContractMaterialRespVos"
      :materialAllList="materialAllList"
      :purchaseOrderId="requestForm.purchaseOrderId"
      @submitChoose="handleSelectMaterial"
    />
    <!-- 到票 -->
    <RequestAdd
      ref="requestAddRef"
      v-if="requestAddShow"
      v-model:requestAddShow="requestAddShow"
      @refreshList="getTicketList"
      :contractId="requestForm.purchaseContractId"
      :contractCode="requestForm.purchaseContractCode"
      :pageType="ticketPageType"
    />
    <!-- 付款申请 -->
    <PaymentAdd
      ref="paymentAddRef"
      v-if="paymentAddShow"
      v-model:requestAddShow="paymentAddShow"
      @refreshList="getPaymentList"
      :contractId="requestForm.purchaseContractId"
      :contractCode="requestForm.purchaseContractCode"
      :pageType="paymentPageType"
    />
    <!-- 入库记录 -->
    <InorderAdd
      v-if="inorderAddShow"
      v-model:addShow="inorderAddShow"
      @refreshList="getInorderList"
      :contractId="requestForm.purchaseContractId"
      :contractCode="requestForm.purchaseContractCode"
      :supplierName="requestForm.distributorName"
      :pageType="inorderPageType"
    />
    <!-- 归档默认0 弹窗 -->
    <el-dialog
      :title="title"
      v-model="auditDialogShow"
      width="600px"
      append-to-body
    >
      <el-form-item label="审核备注：" label-width="90">
        <el-input
          style="width: 100%"
          v-model="auditRemark"
          placeholder=""
          type="textarea"
          maxlength="2000"
          clearable
        />
      </el-form-item>
      <template #footer>
        <div class="dialog-footer">
          <el-button
            style="color: #fff; background-color: rgba(67, 207, 124, 1)"
            v-if="auditResult == 3"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >同意</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 4"
            @click="saveCheck()"
            v-loading="loadingCheck"
            >拒绝</el-button
          >
          <el-button
            style="color: #fff; background-color: rgba(245, 108, 108, 1)"
            v-if="auditResult == 6"
            @click="saveCheck()"
            v-loading="loadingCheck"
          >
            驳回</el-button
          >
          <el-button style="background-color: #fff" @click="closeAudit()"
            >取 消</el-button
          >
        </div>
      </template>
    </el-dialog>
    <!-- 归档1 提交申请人 弹窗 -->
    <el-dialog
      :title="auditDialog1Showtitle"
      v-model="auditDialog1Show"
      width="1000px"
      append-to-body
    >
      <Subapplicant
        v-if="auditDialog1Show"
        @closeauditDialog1="closeauditDialog1"
        @handleBack="handleBack"
        :requestForm="requestForm"
        modeltype="sealcontract"
      ></Subapplicant>
    </el-dialog>
    <!-- 归档2 合同保管员 弹窗 -->
    <el-dialog
      :title="auditDialog2Showtitle"
      v-model="auditDialog2Show"
      width="1000px"
      append-to-body
    >
      <Contractcustodian
        v-if="auditDialog2Show"
        @closeauditDialog2="closeauditDialog2"
        @handleBack="handleBack"
        :requestForm="requestForm"
        modeltype="sealcontract"
      ></Contractcustodian>
    </el-dialog>
  </div>
</template>

<script setup>
import RequestAdd from "./requestAdd.vue";
import PaymentAdd from "../payment/requestAdd.vue";
import InorderAdd from "../../stock/inorder/add.vue";
import Subapplicant from "../../seal/circulation/subapplicant";
import Contractcustodian from "../../seal/circulation/contractcustodian";
import { Picture as IconPicture } from "@element-plus/icons-vue";
import SelectionMaterial from "./selectionMaterial";
import Upload from "@/components/Upload/index";
import { getUserListApi } from "@/api/information/customer";
// import { getProjectListApi } from "@/api/sales/project";
import {
  getSealListApi,
  getRawSealListApi,
  getSourceContract,
  getOrderListApi,
  getOrderMaterialApi,
  getRequestListApi,
  getRequestAllListApi,
  getRequestFilterListApi,
  addSealApi,
  editSealApi,
  getSealDetailApi,
  getTicketListApi,
  getInorderListApi,
  deleteTicketApi,
  checkSealApi,
  getFrameSelectListApi,
  getFrameDetailListApi,
  getProjectListApi,
} from "@/api/purchase/contractSeal";
import { getDictsApi } from "@/api/dict";
import { ElMessage, ElMessageBox } from "element-plus";
import { getSupplierListApi } from "@/api/information/supplier";
import { deletePaymentId } from "@/api/purchase/payment";
import { nextTick } from "vue";

const route = useRoute();
const emit = defineEmits([
  // 客户新增组件显隐
  "contractSealAddShow",
  // 更新客户新增组件显隐
  "update:contractSealAddShow",
  // 刷新父组件表格数据
  "refreshList",
]);
const props = defineProps({
  // 操作类型
  pageType: {
    type: String,
    default: "add",
  },
});

// 折叠栏默认展开
const activeNames = ref(["1", "2", "3", "4", "5", "6", "7"]);
// 客户表单引用
const requestFormRef = ref();
// 联系人表单引用
const contactFormRef = ref();
const inputRef = ref();
// 联系人操作类型
const operateType = ref("");
// 新增联系人表单显隐
const contactAddShow = ref(false);

// 选择审核
const auditDialogShow = ref(false);

let auditDialog1Show = ref(false);
let auditDialog1Showtitle = ref("");
let auditDialog2Show = ref(false);
let auditDialog2Showtitle = ref("");
const pageType = ref(props.pageType);
const loadingCheck = ref(false);
// 选择物料显隐
const selectionMaterialShow = ref(false);
// 详情加载效果
const detailInfoShow = ref(false);
// 输入框引用
const refInput = ref();
// 下拉框引用
const refSelect = ref();
// 联系人当前索引(编辑联系人使用)
const tableIndex = ref(null);
// 合同类型列表
const typeList = ref([]);
// 发票类型
const invoiceTypeList = ref([]);

// 采购类型列表
const purchaseDefaultList = ref([]);
const purchaseTypeList = ref([]);
// 甲方单位
const partyUnitsList = ref([]);
// 单位列表
const unitList = ref([]);
// 采购订单列表
const orderList = ref([]);
// 供应商列表
const suppliereList = ref([]);
// 解除列表
const relieveList = ref([]);
// 项目列表
const projectList = ref([]);
// 请购列表
const requestList = ref([]);
const requestAllList = ref([]);
const requestFilterList = ref([]);
// 采购物料列表
const materialAllList = ref([]);
// 原合同列表
const sourceContractList = ref([]);
const sourceContractList2 = ref([]);
// 合同用印到票列表
const ticketList = ref([]);
// 付款列表
const paymentList = ref([]);
// 入库列表
const inorderList = ref([]);
// 框架协议列表
const frameList = ref([]);
// 到票操作类型
const ticketPageType = ref("");
// 付款操作类型
const paymentPageType = ref("");
// 入库操作类型
const inorderPageType = ref("");
// 客户新增组件显隐
const requestAddShow = ref(false);
// 付款新增组件显隐藏
const paymentAddShow = ref(false);
// 入库新增组件显隐藏
const inorderAddShow = ref(false);
// 到票新增组件引用
const requestAddRef = ref(null);
// 合同用印id
const sealId = ref(null);
//渠道列表
const channelList = ref([]);
// 默认税率列表
const taxRateList = ref([]);

const paymentAddRef = ref(null);
//关联项目名称信息
const projectInfo = ref("");

// 客户表单数据模板
const requestFormTemplate = {
  applicantDate: "", // 申请日期
  applicantId: null, // 申请人id
  remarks: "", // 备注
  type: 0, // 	按钮类型0：存为草稿；1；提交
  deptName: "", // 申请部门
  purchaseProjectListRespVos: [], // 关联项目id
  contractAmount: "",
  contractCheckStatus: null, // 审核状态
  contractType: null, // 合同类型
  frameworkId: null, // 关联框架协议i
  printedDocuments: null, // 	用印文件
  pigeonholeNumber:null, // 应归档份数
  refund:null, // 履约保证金
  purchaseContractCode: "", // 采购合同编号
  purchaseContractMaterialRespVos: [], // 合同用印物料信息对象
  purchaseContractName: "", // 	采购合同名称
  purchaseInqMaterialDetailLitsRespVos: [], // 	请购单物料信息
  purchaseConMaterialByIdRespVos: [], // 	框架协议明细
  purchaseOrderId: null, // 	采购单id
  purchaseOrder: null, // 	采购单编号
  purchaseType: null, // 	采购类型
  secureReason: "", // 	解除的原因
  sourceContract: "", // 	原合同ID
  sourceContractName: "", //原合同名称
  suppFileInfoVos: [], // 	合同附件
  supplierId: null, // 供应商id
  supplierName: "", // 供应商名称
  newContractMoney: null, // 现合同金额
  changeMoney: null, // 变动金额
  purchaseUse: "", // 采购用途
};
// 联系人表单数据模板
const contactFormTemplate = {
  deliveryCycle: "", // 到货周期
  factoryCode: "", // 出厂编号
  manufactureName: "", // 生产厂商名称
  manufacturerId: null, // 生产厂商(也是供应商id)
  manufacturerIdName: "", // 生产厂商全称（详情专用）
  materialCode: "", // 	物料编号
  materialName: "", // 	物料名称
  materialUnit: null, // 	物料单位
  materialUnitName: "", // 物料单位中文
  purchaseApplyId: null, // 关联请购申请表主键id
  purchaseMaterialId: null,
  purchaseNumber: null, // 请购数量
  purchasePrice: null, // 	请购单价
  allPrice: null, // 总价
  purchaseTrackingStatus: null, // 请购跟踪状态
  purchaseTrackingStatusName: "", // 	请购跟踪状态中文
  referenceLink: "", // 参考链接
  remarks: "", // 备注
  suppFileInfoVos: [], // 采购申请物料图片
  supplierId: null, // 供应商id
  supplierIdName: "", // 供应商全称（详情专用）
  supplierName: "", // 供应商名称
  technologyParameter: "", // 技术参数
  channel: null, //渠道
};
const data = reactive({
  // 客户表单
  requestForm: JSON.parse(JSON.stringify(requestFormTemplate)),
  // 联系人表单
  contactForm: JSON.parse(JSON.stringify(contactFormTemplate)),
  // 客户表单校验规则
  queryRules: {
    applicantDate: [
      { required: true, message: "请选择申请日期", trigger: "change" },
    ],
    applicantId: [
      { required: true, message: "请选择经办人", trigger: "change" },
    ],
    contractType: [
      { required: true, message: "请选择合同类型", trigger: "change" },
    ],
    purchaseType: [
      { required: true, message: "请选择采购类型", trigger: "change" },
    ],
    partyUnits: [
      { required: true, message: "请选择甲方单位", trigger: "change" },
    ],
    purchaseInqMaterialDetailLitsRespVos: [
      { required: true, message: "请选择关联请购单", trigger: "change" },
    ],
    
    supplierName: [
      { required: true, message: "请输入供应商", trigger: "change" },
    ],
    purchaseUse: [
      { required: true, message: "请输入采购用途", trigger: "blur" },
    ],
    supplierId: [
      { required: true, message: "请选择供应商", trigger: "change" },
    ],
    contractAmount: [
      { required: true, message: "请输入合同金额", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value > 9999999999) {
            callback(new Error("最大可输入十位数字"));
          } else if (value < 0) {
            callback(new Error("值不能小于0"));
          } else {
            if (value.toString().split(".")[1]?.length > 2) {
              callback(new Error("小数点后最多两位"));
            } else {
              callback();
            }
          }
        },
      },
    ],
    changeMoney: [
      { required: true, message: "请输入变动金额", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value > 9999999999 || value < -9999999999) {
            callback(new Error("最大可输入十位数字"));
          } else {
            if (value.toString().split(".")[1]?.length > 2) {
              callback(new Error("小数点后最多两位"));
            } else {
              callback();
            }
          }
        },
      },
    ],
    sourceContractName: [
      { required: true, message: "请选择原合同", trigger: "change" },
    ],
    sourceContract: [
      { required: true, message: "请选择原合同", trigger: "change" },
    ],
    secureReason: [
      { required: true, message: "请选择解除原因", trigger: "change" },
    ],
    printedDocuments: [
      { required: true, message: "请选择用印文件", trigger: "change" },
      {
        validator: (rule, value, callback) => {
          if (value < 1 || value > 99) {
            callback(new Error("用印文件为0到99之间的整数"));
          } else {
            callback();
          }
        },
        trigger: "blur",
      },
    ],
    pigeonholeNumber: [
      { required: true, message: "请输入应归档份数", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value < 1 || value > 99) {
            callback(new Error("应归档份数为0到99之间的整数"));
          } else {
            callback();
          }
        },
        trigger: "blur",
      },
    ],
    frameworkId: [
      { required: true, message: "请选择关联框架协议", trigger: "change" },
    ],
    // purchaseOrderId: [
    //   { required: true, message: "请选择关联采购单", trigger: "change" },
    // ],
    suppFileInfoVos: [
      { required: true, message: "请上传合同附件", trigger: "change" },
    ],
  },
  // 联系人表单校验规则
  queryContactRules: {
    materialName: [
      {
        required: true,
        message: "请输入物料名称",
        trigger: ["blur", "change"],
      },
    ],
    factoryCode: [
      { required: true, message: "请输入出厂型号", trigger: "blur" },
    ],
    technologyParameter: [
      { required: true, message: "请输入技术参数", trigger: "blur" },
    ],
    materialUnit: [
      { required: true, message: "请选择单位", trigger: "change" },
    ],
    purchaseNumber: [
      { required: true, message: "请输入采购数量", trigger: "blur" },
    ],
    budgetedPrice: [
      { required: true, message: "请输入预算单价", trigger: "blur" },
    ],
    purchasePrice: [
      { required: true, message: "请输入询价单价", trigger: "blur" },
    ],
    taxRate: [{ required: true, message: "请输入税率", trigger: "blur" }],
    freight: [
      { required: true, message: "请输入运费", trigger: "blur" },
      {
        validator: (rule, value, callback) => {
          if (value > 999999 || value < 0) {
            callback(new Error("运费为0到999999之间的数字"));
          } else {
            if (value.toString().split(".")[1]?.length > 2) {
              callback(new Error("运费小数点后最多两位"));
            } else {
              callback();
            }
          }
        },
      },
    ],
    invoiceType: [
      { required: true, message: "请选择发票类型", trigger: "change" },
    ],
    deliveryCycle: [
      { required: true, message: "请输入到货周期", trigger: "blur" },
    ],
    channel: [{ required: true, message: "请选择渠道", trigger: "change" }],
  },
  // 角色列表
  contactTypeList: [],
  // 所属行业列表
  industryList: [],
  // 用户列表
  userList: [],
  auditRemark: "",
  auditResult: "",
  applyId: "",
});

const {
  requestForm,
  contactForm,
  queryRules,
  queryContactRules,
  contactTypeList,
  industryList,
  userList,
  auditRemark,
  auditResult,
  applyId,
} = toRefs(data);

const handleCheckBtn2 = (requestFormRef, type, title) => {
  if (type == 3) {
    switch (requestForm.value.nextAudit.flowIntype) {
      case "0":
        auditRemark.value = "同意";
        auditResult.value = type;
        applyId.value = requestForm.value.purchaseContractId;
        auditDialogShow.value = true;
        loadingCheck.value = false;
        break;
      case "1":
        //提交申请人
        auditDialog1Show.value = true;
        auditDialog1Showtitle.value = "资料归档";
        break;
      case "2":
        //合同保管人
        auditDialog2Show.value = true;
        auditDialog2Showtitle.value = "资料归档";
        break;

      default:
        break;
    }
  } else {
    auditRemark.value = "";
    auditResult.value = type;
    applyId.value = requestForm.value.purchaseContractId;
    auditDialogShow.value = true;
    loadingCheck.value = false;
  }
};

const saveCheck = async () => {
  if (auditRemark.value === null || auditRemark.value === "") {
    ElMessage.error("审核备注不能为空");
    return;
  }

  const obj = {
    contractCheckStatus: auditResult.value,
    purchaseContractId: applyId.value,
    auditRemark: auditRemark.value,
    oldPurchaseContractId: requestForm.value.sourceContract,
  };
  try {
    loadingCheck.value = true;
    const res = await checkSealApi(obj);
    auditDialogShow.value = false;

    //loadingCheck.value =false;

    if (res.code === 200) {
      ElMessage.success(res.msg);
    } else {
      ElMessage.error(res.msg);
      return;
    }
    loadingCheck.value = false;
    emit("update:contractSealAddShow", false);
    emit("refreshList", false);
  } catch (error) {
    loadingCheck.value = false;
    emit("update:contractSealAddShow", false);
    emit("refreshList", false);
    // ElMessage.error(error);
  }
};

const closeAudit = () => {
  auditRemark.value = "";
  auditResult.value = "";
  applyId.value = "";
  auditDialogShow.value = false;
};

const closeauditDialog1 = () => {
  console.log('关闭--')
  auditDialog1Show.value = false;
};

const closeauditDialog2 = () => {
  console.log('关闭--')
  auditDialog2Show.value = false;
};
/**
 * @description: 保存
 * @param {Object} requestFormRef 客户表单引用
 */
const handleAddSave = async (requestFormRef, type) => {
  if (!requestFormRef) return;
  await requestFormRef.validate(async (valid, fields) => {
    if (valid) {
      let materialRespVos = requestForm.value.purchaseContractMaterialRespVos;

      if (
        (materialRespVos && materialRespVos.length > 0) ||
        requestForm.value.contractType == 2 ||
        (!requestForm.value.purchaseOrderCode &&
          !requestForm.value.purchaseInqMaterialDetailLitsRespVos?.length)
      ) {
        let visible = materialRespVos.find(
          (element) => element.purchaseNumber == undefined
        );
        if (visible == undefined || requestForm.value.contractType == 2) {
          ElMessageBox.confirm("确定保存以上数据吗？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
            confirmButtonClass: "confirmBtnClass",
            cancelButtonClass: "cancelBtnClass",
          })
            .then(async () => {
              requestForm.value.purchaseConMaterialByIdRespVos.forEach(
                (item) => {
                  item.quantity = Number(item.quantity);
                }
              );

              requestForm.value.type = type;
              let res;
              if (!requestForm.value.purchaseContractId) {
                // 新增客户
                res = await addSealApi(requestForm.value);
              } else {
                // 编辑客户
                res = await editSealApi(requestForm.value);
              }
              if (res.code === 200) {
                emit("update:contractSealAddShow", false);
                emit("refreshList", false);
                ElMessage.success(res.msg);
                requestForm.value = JSON.parse(
                  JSON.stringify(requestFormTemplate)
                );
              } else {
                ElMessage.error(res.msg);
              }
            })
            .catch(() => {});
        } else {
          ElMessage({
            message: "请完善物料信息",
            type: "warning",
          });
        }
      } else {
        ElMessage({
          message: "请选择物料信息",
          type: "warning",
        });
      }
    }
  });
};

/**
 * @description: 返回
 */
const handleBack = () => {
  if (props.pageType === "detail" || props.pageType === "check") {
    emit("updateFollowAddShow", false);
    emit("update:contractSealAddShow", false);
    requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
  } else {
    ElMessageBox.confirm("确定返回上一级吗?以上数据未保存将会丢失!", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
      confirmButtonClass: "confirmBtnClass",
      cancelButtonClass: "cancelBtnClass",
    })
      .then(async () => {
        emit("update:contractSealAddShow", false);
        requestForm.value = JSON.parse(JSON.stringify(requestFormTemplate));
      })
      .catch(() => {});
  }
};

/**
 * @description: 处理手动输入
 */
const handleHand = () => {
  contactForm.value = JSON.parse(JSON.stringify(contactFormTemplate));
  contactFormRef.value.resetFields();
};

/**
 * @description: 处理选择物料
 */
const handleMaterial = () => {
  requestForm.contractType;
  if (requestForm.value.contractType !== null) {
    selectionMaterialShow.value = true;
  } else {
    ElMessage.warning("请先选择合同类型");
  }
};

/**
 * @description: 处理物料选择
 */
const handleSelectMaterial = (value) => {
  if (value.length) {
    requestForm.value.purchaseContractMaterialRespVos.push(...value);
    selectionMaterialShow.value = false;
    if (requestForm.value.purchaseOrderId) {
      handleRequest();
    }
  } else {
    ElMessage.info("请选择物料");
  }
};
/* 选择渠道 */
const changeChannel = (row) => {
  var obj = {};
  obj = channelList.value.find(function (i) {
    return i.value === row;
  });
  contactForm.value.channelName = obj.label;
};

/**
 * @description: 处理供应商、生产厂家选择
 */
// const handleSuppliereSelect = (value, index) => {
//   if (index == 1) {
//     contactForm.value.supplierId = value.supplierId;
//   } else {
//     requestForm.value.supplierId = value.supplierId;
//   }
// };

// const handleSuppliereInput = (value) => {
//   if (value == 1) {
//     contactForm.value.supplierId = null;
//   } else {
//     requestForm.value.supplierId = null;
//   }
// };

// const querySearch = (queryString, cb) => {
//   const results = queryString
//     ? suppliereList.value.filter(createFilter(queryString))
//     : suppliereList.value;
//   cb(results);
// };
/* 原合同input框搜索 */
const contractSearch = (queryString, cb) => {
  const results = queryString
    ? sourceContractList.value.filter(createFilter(queryString))
    : sourceContractList.value;
  cb(results);
};

/* 关联采购单input框搜索 */
const purchaseSearch = (queryString, cb) => {
  let results = queryString
    ? orderList.value.filter(createFilter(queryString))
    : orderList.value;
  if (queryString == "null") {
    results = orderList.value;
  }
  cb(results);
};
/* 关联采购单下拉框 */
const handlePurchaseSelect = (value) => {
  if (value.checkMaterialStatus == 1) {
    requestForm.value.purchaseOrderId = value.purchaseOrderId;
    handleOrderChange(value.purchaseOrderId);
  } else {
    requestForm.value.purchaseOrderId = null;
    requestForm.value.purchaseOrderCode = null;
    inputRef.value.blur();
    ElMessage.warning("请前往采购订单管理，完善物料后再新增合同信息");
  }
};

const handlePurchaseChange = (value) => {
  if (!value) {
    requestForm.value.purchaseOrderId = null;
    requestForm.value.purchaseOrderCode = null;
  }
};

const handleContractSelect = (value) => {
  console.log("handleContractSelect");
  console.log(value);
  requestForm.value.sourceContract = value.purchaseContractId;
  requestForm.value.supplierName = value.distributorName;
  requestForm.value.supplierId = value.supplierId;
  requestForm.value.partyUnits = value.partyUnits;
  requestForm.value.contractAmount = value.contractAmount;
};

const handleContractSelect2 = (value) => {
  if (value) {
    sourceContractList2.value.forEach((item) => {
      if (item.purchaseContractId == value) {
        requestForm.value.originType = item.contractType;
        requestForm.value.purchaseType = item.purchaseType;
        requestForm.value.supplierId = item.supplierId;
        requestForm.value.supplierName = item.supplierName;
        requestForm.value.printedDocuments = item.printedDocuments;
        requestForm.value.contractAmount = item.contractAmount;
        requestForm.value.purchaseOrderCode = item.purchaseOrderCode;
        requestForm.value.purchaseOrderId = item.purchaseOrderId;
        requestForm.value.partyUnits = item.partyUnits;
        requestForm.value.purchaseInqMaterialDetailLitsRespVos =
          item.purchaseInqMaterialDetailLitsRespVos || [];
        requestForm.value.purchaseProjectListRespVos =
          item.purchaseProjectListRespVos || [];
        requestForm.value.purchaseContractMaterialRespVos =
          item.purchaseConMaterialRespVos || [];
        requestForm.value.purchaseContractMaterialRespVos.forEach((item) => {
          item.allPrice = (
            item.purchasePrice * item.purchaseNumber +
            (item.freight ? item.freight : 0)
          ).toFixed(2);
        });

        /* 根据合同类型修改采购类型 */
        let targetArr = [];
        if (item.contractType == 0) {
          targetArr = ["低空防御", "周界防护"];
        } else if (item.contractType == 1) {
          targetArr = ["固定资产", "员福礼品"];
        }
        if (targetArr.length == 0) {
          purchaseTypeList.value = [...purchaseDefaultList.value];
        } else {
          purchaseTypeList.value = purchaseDefaultList.value.filter(
            (obj) => targetArr.indexOf(obj.label) !== -1
          );
        }
      }
    });
  } else {
    requestForm.value.originType = null;

    requestForm.value.purchaseType = null;
    requestForm.value.supplierId = null;
    requestForm.value.supplierName = "";
    requestForm.value.printedDocuments = "";
    requestForm.value.contractAmount = "";
    requestForm.value.purchaseOrderCode = "";
    requestForm.value.purchaseOrderId = null;
    requestForm.value.partyUnits = null;
    requestForm.value.purchaseInqMaterialDetailLitsRespVos = [];
    requestForm.value.purchaseProjectListRespVos = [];
    requestForm.value.purchaseContractMaterialRespVos = [];
  }
  getRequestList();

  // requestForm.value.sourceContract = value.purchaseContractId;
  // requestForm.value.supplierName = value.distributorName;
  // requestForm.value.supplierId = value.supplierId;
  // // 0 项目采购  // 1 综合采购
  // requestForm.value.originType = 0
};

const createFilter = (queryString) => {
  return (restaurant) => {
    return (
      restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
    );
  };
};

/**
 * @description: 处理审核状态相关按钮
 * @param {String} type  类型
 * @param {String} title 标题
 */
const handleCheckBtn = (contractFormRef, type, title) => {
  ElMessageBox.confirm(`确定${title}以上数据吗？`, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    confirmButtonClass: "confirmBtnClass",
    cancelButtonClass: "cancelBtnClass",
  })
    .then(async () => {
      const obj = {
        contractCheckStatus: type,
        purchaseContractId: requestForm.value.purchaseContractId,
        purchaseInqMaterialDetailLitsRespVos:
          requestForm.value.purchaseInqMaterialDetailLitsRespVos,
        purchaseOrderId: requestForm.value.purchaseOrderId,
      };
      const res = await checkSealApi(obj);
      if (res.code === 200) {
        emit("update:contractSealAddShow", false);
        emit("refreshList", false);
        ElMessage.success(res.msg);
        contractForm.value = JSON.parse(JSON.stringify(contractFormTemplate));
      } else {
        ElMessage.error(res.msg);
      }
    })
    .catch(() => {});
};

/**
 * @description: 处理类型选择
 * @param {Number} value 选择值
 */
const handleType = (value) => {
  let name = "";
  if (value == 3) {
    name = "协议采购";
  } else if (value == 4) {
    name = "小额垫付";
  } else {
    name = requestForm.value.purchaseContractName;
    // name = "";
  }
  requestForm.value = {
    ...requestFormTemplate,
    purchaseContractCode: requestForm.value.purchaseContractCode,
    purchaseContractName: name,
    applicantDate: requestForm.value.applicantDate,
    applicantId: requestForm.value.applicantId,
    deptName: requestForm.value.deptName,
    contractType: requestForm.value.contractType,
  };
  /* 根据合同类型修改采购类型 */
  let targetArr = [];
  if (value == 0 || value == 3) {
    targetArr = ["低空防御", "周界防护"];
  } else if (value == 1) {
    targetArr = ["固定资产", "员福礼品"];
    // "项目申报",
    //   "租赁装修",
    //   "行政月结",
    //   "人资服务",
    //   "企划制作",
    //   "法务财务",
    //   "其他服务",
  } else if (value == 6) {
    targetArr = ["低空防御", "周界防护", "固定资产", "员福礼品"];
  }
  if (targetArr.length == 0) {
    purchaseTypeList.value = [...purchaseDefaultList.value];
  } else {
    purchaseTypeList.value = purchaseDefaultList.value.filter(
      (obj) => targetArr.indexOf(obj.label) !== -1
    );
  }
  getRequestList();
};

/**
 * @description: 处理人员选择
 * @param {Number} value 选择值
 */
const handleUserChange = (value) => {
  if (value) {
    const selectUser = userList.value.find((item) => item.userId === value);
    if (selectUser) {
      requestForm.value.deptName = selectUser.dept.deptName;
    }
  } else {
    requestForm.value.deptName = "";
  }
};

/**
 * @description: 处理单位选择
 * @param {Number} value 选择值
 */
const handleUnitChange = (value) => {
  contactForm.value.materialUnitName =
    unitList.value.find((item) => item.value === value)?.label || "";
};
/* 关联项目下拉框 */
const handleProject = (data) => {
  let dataName = [];
  data.forEach((item) => {
    dataName.push(item.projectCode + " " + item.projectName);
  });
  projectInfo.value = dataName.toString();
};

/**
 * @description: 处理请购单选择
 * @param {Number} value 选择值
 */
const handleRequestChange = () => {
  requestForm.value.purchaseProjectListRespVos = [];
  let dataName = [];

  requestForm.value.purchaseInqMaterialDetailLitsRespVos.forEach((item) => {
    // 判断当前请购单有项目且项目只有一个
    if (
      item.projectId &&
      !requestForm.value.purchaseProjectListRespVos.some(
        (itemArr) => itemArr.projectId === item.projectId
      )
    ) {
      dataName.push(item.projectCode + " " + item.projectName);
      requestForm.value.purchaseProjectListRespVos.push({
        projectCode: item.projectCode,
        projectId: item.projectId,
        projectName: item.projectName,
      });
    }
    projectInfo.value = dataName.toString();
  });
};

/**
 * @description: 处理采购单选择
 * @param {Number} value 选择值
 */
const handleSupplierChange = async (value) => {
  requestForm.value.frameworkId = null;
  requestForm.value.purchaseConMaterialByIdRespVos = [];
  // if (value) {
  //   // 框架协议
  //   await getFrameSelectListApi(value).then((res) => {
  //     if (res) {
  //       frameList.value = res;
  //     }
  //   });
  // } else {
  //   frameList.value = [];
  // }
};

/**
 * @description: 处理框架协议选择
 * @param {Number} value 选择值
 */
const handleFrameChange = async (value) => {
  // requestForm.value.frameworkId = null
  if (value) {
    frameList.value.forEach((item) => {
      if (item.purchaseContractId === value) {
        requestForm.value.purchaseContractCode = item.purchaseContractCode;
      }
    });
    // 框架协议
    await getFrameDetailListApi(value).then((res) => {
      if (res) {
        requestForm.value.purchaseConMaterialByIdRespVos = res;
        requestForm.value.purchaseConMaterialByIdRespVos.forEach((item) => {
          item.quantity = 0;
        });
      }
    });
  } else {
    requestForm.value.purchaseConMaterialByIdRespVos = [];
  }
};

/**
 * @description: 处理采购单选择
 * @param {Number} value 选择值
 */
const handleOrderChange = async (value) => {
  // 回显物料信息
  const res = await getOrderMaterialApi({
    contractType: requestForm.value.contractType,
    purchaseOrderId: requestForm.value.purchaseOrderId,
  });
  if (res) {
    // requestForm.value.purchaseInqMaterialDetailLitsRespVos = [];
    // requestForm.value.purchaseProjectListRespVos = [];
    materialAllList.value = [];
    materialAllList.value = JSON.parse(JSON.stringify(res));
    requestForm.value.purchaseContractMaterialRespVos = res;
    // 回显请购单列表
    handleRequest();
  }
  // requestList.value = requestForm.value.purchaseInqMaterialDetailLitsRespVos;
  // 请购单列表
  //
};

/**
 * @description: 处理物料回显请购单
 */
const handleRequest = () => {
  requestForm.value.purchaseInqMaterialDetailLitsRespVos = [];
  requestForm.value.purchaseProjectListRespVos = [];
  let dataName = [];
  requestForm.value.purchaseContractMaterialRespVos.forEach((item) => {
    item.allPrice = (
      item.purchasePrice * item.purchaseNumber +
      (item.freight ? item.freight : 0)
    ).toFixed(2);
    item.purchaseInqMaterialDetailLitsRespVos.forEach((reqItem) => {
      // if(reqItem.purchaseTrackingStatus === 1) {
      requestForm.value.purchaseInqMaterialDetailLitsRespVos.push(reqItem);
      // 判断当前请购单有项目且项目只有一个
      if (
        reqItem.projectId &&
        !requestForm.value.purchaseProjectListRespVos.some(
          (itemArr) => itemArr.projectId === reqItem.projectId
        )
      ) {
        dataName.push(reqItem.projectCode + " " + reqItem.projectName);
        requestForm.value.purchaseProjectListRespVos.push({
          projectCode: reqItem.projectCode,
          projectId: reqItem.projectId,
          projectName: reqItem.projectName,
        });
      }
      // }
    });
  });
  projectInfo.value = dataName.toString();
};

/**
 * @description: 获取关联请购单列表
 */
const getRequestList = async () => {
  const res = await getRequestListApi({
    purchaseContractId: requestForm.value.purchaseContractId,
  });
  if (res) {
    requestList.value = res;
  }
  let res2;
  if (props.pageType === "add") {
    res2 = await getRequestAllListApi({
      checkStatus: 3,
      purchaseContractId: [6].includes(requestForm.value.contractType)
        ? requestForm.value.sourceContract
        : requestForm.value.purchaseContractId,
    });
  } else {
    res2 = await getRequestAllListApi({
      checkStatus: 3,
      purchaseContractId: requestForm.value.purchaseContractId,
    });
  }
  requestAllList.value = [];
  if (res2) {
    requestAllList.value = res2;
  }

  const res3 = await getRequestFilterListApi();
  requestFilterList.value = [];
  if (res3) {
    console.log("请购单列表");
    console.log(res3);
    requestFilterList.value = res3;
  }
};

/**
 * @description: 预览照片
 * @param {String} img 图片地址
 */
const showImg = (img) => {
  let imgArr = [];
  imgArr.push(img);
  return imgArr;
};

/**
 * @description: 计算总价
 * @param {Number} value 选择值
 */
const handlePrice = () => {
  // 预算： 单价*数量
  if (contactForm.value.budgetedPrice && contactForm.value.purchaseNumber) {
    contactForm.value.budgeteAllPrice = (
      contactForm.value.budgetedPrice * contactForm.value.purchaseNumber
    ).toFixed(2);
  }
  // 总金额： 单价*数量+运费
  if (contactForm.value.purchasePrice && contactForm.value.purchaseNumber) {
    let freight = contactForm.value.freight
      ? Number(contactForm.value.freight)
      : 0;
    contactForm.value.allPrice = (
      contactForm.value.purchasePrice * contactForm.value.purchaseNumber +
      freight
    ).toFixed(2);
  }
  // 税额： 单价 / (1+税率) * 税率
  if (contactForm.value.purchasePrice && contactForm.value.taxRate) {
    contactForm.value.taxAmount = (
      (contactForm.value.purchasePrice /
        (1 + contactForm.value.taxRate * 0.01)) *
      contactForm.value.taxRate *
      0.01
    ).toFixed(2);
  }

  // 不含税金额： 单价 / (1+税率) * 税率
  if (contactForm.value.purchasePrice && contactForm.value.taxAmount) {
    contactForm.value.noTaxAmount = (
      contactForm.value.purchasePrice - contactForm.value.taxAmount
    ).toFixed(2);
  }
};

/**
 * @description: 计算变动金额
 * @param {Number} value 选择值
 */
const handleChangePrice = () => {
  // 现合同金额： 原合同金额 + 变动金额
  if (requestForm.value.changeMoney && requestForm.value.contractAmount) {
    requestForm.value.newContractMoney =
      Number(requestForm.value.contractAmount) +
      Number(requestForm.value.changeMoney);
  }
};

/**
 * @description: 新增到票
 */
const handleAddTicket = () => {
  ticketPageType.value = "add";
  requestAddShow.value = true;
};

/**
 * @description: 新增付款申请
 */
const handleAddPayment = () => {
  paymentPageType.value = "add";
  paymentAddShow.value = true;
};

/**
 * @description: 新增入库
 */
const handleAddInorder = () => {
  inorderPageType.value = "add";
  inorderAddShow.value = true;
};

/**
 * @description: 新增、编辑联系人
 * @param {Object} contactFormRef 联系人表单引用
 */
const handleContactAdd = async (contactFormRef) => {
  if (!contactFormRef) return;
  await contactFormRef.validate(async (valid) => {
    if (valid) {
      if (operateType.value === "edit") {
        requestForm.value.purchaseContractMaterialRespVos[tableIndex.value] =
          JSON.parse(JSON.stringify(contactForm.value));
      } else {
        requestForm.value.purchaseContractMaterialRespVos.push(
          JSON.parse(JSON.stringify(contactForm.value))
        );
      }
      contactForm.value = JSON.parse(JSON.stringify(contactFormTemplate));
      contactFormRef.resetFields();
      nextTick(() => {
        refInput.value.focus();
        if (operateType.value == "edit") {
          contactAddShow.value = false;
        }
      });
    } else {
      console.log("error submit!");
    }
  });
};

/**
 * @description: 文件上传成功处理
 * @param {Object} response 文件信息
 */
function uploadSuccess(response) {
  requestFormRef.value.clearValidate("suppFileInfoVos");
  requestForm.value.suppFileInfoVos.push({ ...response, businessType: 7 });
}

/**
 * @description: 删除文件
 * @param {Number} index 当前文件索引
 */
function uploadRemove(index) {
  requestForm.value.suppFileInfoVos.splice(index, 1);
}

/**
 * @description: 处理联系人操作
 */
const handleContactOperate = () => {
  contactAddShow.value = true;
  operateType.value = "add";
  nextTick(() => {
    refInput.value.focus();
  });
};

/**
 * @description: 联系人返回
 */
const handleRequestBack = () => {
  contactAddShow.value = false;
  nextTick(() => {
    refSelect.value.focus();
  });
};

/**
 * @description: 处理合计
 */
const getSummaries = (param) => {
  const { columns, data } = param;
  if (data) {
    const sums = [];
    columns.forEach((column, index) => {
      if (index === 0) {
        sums[index] = "合计";
        return;
      }
      const values = data.map((item) => Number(item[column.property]));
      // 只对amount这一列进行总计核算。
      if (
        column.property === "purchaseNumber" ||
        column.property === "budgetedPrice" ||
        column.property === "purchasePrice" ||
        // column.property === "taxRate" ||
        column.property === "taxAmount" ||
        column.property === "freight" ||
        column.property === "noTaxAmount" ||
        column.property === "allPrice" ||
        column.property === "budgeteAllPrice"
      ) {
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          if (column.property !== "purchaseNumber") {
            sums[index] = sums[index].toFixed(2); // 保留2位小数，解决小数列合计精度缺失的问题
          }
          // sums[index] += "元";
        } else {
          sums[index] = "";
        }
      }
    });
    if (props.pageType === "add" || props.pageType === "edit") {
      // sums[16] = sums[11] * sums[8] + sums[15];
      // sums[10] = sums[9] * sums[8];
      // sums[15] = null;
      // 14总价 9单价 6数量
      // sums[15] = sums[10] * sums[7] + sums[14];
      // sums[9] = sums[8] * sums[7];
      // sums[14] = null;
    } else {
      // sums[16] = sums[11] * sums[8] + sums[15];
      // sums[10] = sums[9] * sums[8];
      // sums[15] = null;
      // 14总价 9单价 6数量
      // sums[15] = sums[10] * sums[7] + sums[14];
      // sums[9] = sums[8] * sums[7];
      // sums[14] = null;
    }
    return sums;
  }
};

/**
 * @description: 处理合计
 */
const getSummariesTicket = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    }
    const values = data.map((item) => Number(item[column.property]));
    // 只对amount这一列进行总计核算。
    if (column.property === "invoiceAmount") {
      if (!values.every((value) => isNaN(value))) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        // sums[index] += "元";
      } else {
        sums[index] = "";
      }
    }
  });
  return sums;
};

/**
 * @description: 处理本次使用数量
 */
const handleQuantity = (row, index) => {
  if (Number(row.quantity) < 0) {
    requestForm.value.purchaseConMaterialByIdRespVos[index].quantity = 0;
  }
  if (Number(row.quantity) > Number(row.remainingQuantity)) {
    requestForm.value.purchaseConMaterialByIdRespVos[index].quantity = Number(
      row.remainingQuantity
    );
  }
  console.log("处理本次使用数量");
  // requestForm.value.purchaseConMaterialByIdRespVos[index].quantity = Number(requestForm.value.purchaseConMaterialByIdRespVos[index].quantity)
  console.log(requestForm.value.purchaseConMaterialByIdRespVos[index].quantity);
};

/**
 * @description: 处理服务时间计算
 * @param {Number} value 选择值
 */
 const handleServeTime = (flag) => {
  if (requestForm.value.startDate && requestForm.value.endDate) {
    let time1 = new Date(requestForm.value.startDate).getTime();
    let time2 = new Date(requestForm.value.endDate).getTime();
    if (time2 < time1) {
      if (flag == 1) {
        requestForm.value.startDate = "";
      } else {
        requestForm.value.endDate = "";
      }
      requestForm.value.serviceTime = "";
      return ElMessage.warning("截止日期不能早于起始日期");
    }
    requestForm.value.serviceTime = dateDiffInDays(
      requestForm.value.startDate,
      requestForm.value.endDate
    );
  }

  if(!requestForm.value.startDate || !requestForm.value.endDate) {
    requestForm.value.serviceTime = ''
  }
  function dateDiffInDays(startDate, endDate) {
    startDate = new Date(startDate);
    endDate = new Date(endDate);
    let timeDiff = Math.abs(endDate - startDate),
      daysDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
    return daysDiff;
  }
};

/**
 * @description: 处理合计
 */
const getSummariesPaymentList = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = "合计";
      return;
    }
    if (data && data.length) {
      const values = data.map((item) => Number(item[column.property]));
    }
    // 只对amount这一列进行总计核算。
    if (column.property === "invoiceAmount") {
      if (!values.every((value) => isNaN(value))) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        // sums[index] += "元";
      } else {
        sums[index] = "";
      }
    }
  });
  return sums;
};

/**
 * @description: 处理联系人表格操作
 * @param {String} type 操作类型
 * @param {Object} row  当前行数据
 * @param {Number} tabIndex 表格当前索引
 */
const handleOperate = (type, row, tabIndex) => {
  if (type === "edit") {
    tableIndex.value = tabIndex;
    contactForm.value = {
      ...JSON.parse(JSON.stringify(row)),
      suppFileInfoVos: JSON.parse(JSON.stringify(row)).suppFileInfoVos
        ? JSON.parse(JSON.stringify(row)).suppFileInfoVos
        : [],
    };
    contactForm.value.allPrice =
      contactForm.value.purchasePrice * contactForm.value.purchaseNumber
        ? (
            contactForm.value.purchasePrice * contactForm.value.purchaseNumber
          ).toFixed(2)
        : null;
    contactAddShow.value = true;
    operateType.value = "edit";
    nextTick(() => {
      refInput.value.focus(); // 聚焦
    });
  } else {
    requestForm.value.purchaseContractMaterialRespVos.splice(tabIndex, 1);
    if (requestForm.value.purchaseOrderId) {
      handleRequest();
    }
  }
};

/**
 * @description: 付款记录表格操作
 * @param {String} type 类型
 * @param {Object} row  当前行数据
 */
const handlePayOperate = async (type, row) => {
  switch (type) {
    case "edit":
      paymentPageType.value = type;
      paymentAddShow.value = true;
      nextTick(() => {
        paymentAddRef.value.handleDetailInfo(row.paymentApplyId);
      });
      break;
    case "delete":
      ElMessageBox.confirm("此操作将删除该付款申请信息，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        confirmButtonClass: "confirmBtnClass",
        cancelButtonClass: "cancelBtnClass",
        type: "warning",
      })
        .then(async () => {
          const res = await deletePaymentId(row.paymentApplyId);
          if (res.code === 200) {
            ElMessage.success(res.msg);
            handleDetailInfo(sealId.value);
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {});
      break;

    default:
      break;
  }
};
/**
 * @description: 表格操作
 * @param {String} type 类型
 * @param {Object} row  当前行数据
 */
const handleTicketOperate = async (type, row) => {
  switch (type) {
    case "edit":
      ticketPageType.value = type;
      requestAddShow.value = true;
      nextTick(() => {
        requestAddRef.value.handleDetailInfo(row.contractRelationInvoiceId);
      });
      break;
    case "delete":
      ElMessageBox.confirm("此操作将删除该到票信息，是否继续？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        confirmButtonClass: "confirmBtnClass",
        cancelButtonClass: "cancelBtnClass",
        type: "warning",
      })
        .then(async () => {
          const res = await deleteTicketApi(row.contractRelationInvoiceId);
          if (res.code === 200) {
            ElMessage.success(res.msg);
            getTicketList();
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {});
      break;

    default:
      break;
  }
};

/**
 * @description: 处理详情信息
 * @param {Number} id
 */
const handleDetailInfo = async (id) => {
  // getDicts();

  sealId.value = id;
  try {
    detailInfoShow.value = true;
    // 合同用印详情接口
    const res = await getSealDetailApi(id);
    if (res) {
      requestForm.value = {
        ...res.purchaseContractInfoRespVo,
        sourceContractName: res.purchaseContractInfoRespVo.ourceContractName,
        purchaseContractMaterialRespVos: res.purchaseConMaterialRespVos
          ? res.purchaseConMaterialRespVos
          : [],
        nextAudit: res.nextAudit,
        archiveFileList:res.archiveFileList || []
      };
      // 已用数量赋值为0
      // requestForm.value.purchaseConMaterialByIdRespVos.forEach(item => {
      //     item.quantity = 0
      //   })
      requestForm.value.originType =
        res.purchaseContractInfoRespVo.oldContractType;
      getRequestList();
      // 采购订单列表
      await getOrderListApi({
        orderCheckStatus: 3,
        purchaseContractId: requestForm.value.purchaseContractId,
      }).then((res) => {
        if (res) {
          orderList.value = res;
          res.forEach((item) => {
            item.value = item.purchaseOrderCode;
          });
        }
      });
      if (res.purchaseConMaterialRespVos?.length > 0) {
        requestForm.value.purchaseContractMaterialRespVos.forEach((item) => {
          item.allPrice = (
            item.purchasePrice * item.purchaseNumber +
            (item.freight ? item.freight : 0)
          ).toFixed(2);
          item.supplierName = item.distributorName;
        });
      }
      // if (requestForm.value.supplierId) {
      //   // 框架协议列表
      //   await getFrameSelectListApi(requestForm.value.supplierId).then(
      //     (res) => {
      //       if (res) {
      //         frameList.value = res;
      //       }
      //     }
      //   );
      // }
      // 付款记录
      paymentList.value = res.payApplyInfoRespVos;

      //原合同
      requestForm.value.sourceContract =
        res.purchaseContractInfoRespVo?.sourceContract;
      // 原合同列表
      await getRawSealListApi({}, { contractCheckStatus: 3 }).then((res) => {
        if (res.code === 200) {
          res.rows.forEach((item) => {
            if (
              item.purchaseContractId ==
              requestForm.value.sourceContract * 1
            ) {
              requestForm.value.sourceContractName = item.purchaseContractName;
            }
          });
        }
      });

      //获取关联采购单的列表数据（选择物料页面使用）
      const result = await getOrderMaterialApi({
        contractType: res.contractType,
        purchaseOrderId: res.purchaseOrderId,
      });
      materialAllList.value = [];
      materialAllList.value = JSON.parse(JSON.stringify(result));
      //关联请购单
      let dataName = [];
      res.purchaseContractInfoRespVo?.purchaseProjectListRespVos.forEach(
        (item) => {
          dataName.push(item.projectCode + " " + item.projectName);
        }
      );
      projectInfo.value = dataName.toString();
      getTicketList();
      getInorderList();
      // getPaymentList()
      getRequestList();
    }
    detailInfoShow.value = false;
  } catch (error) {
    detailInfoShow.value = false;
  }
};

/**
 * @description: 处理到票
 * @param {Number} id
 */
const getTicketList = async () => {
  // 合同用印到票列表
  await getTicketListApi(requestForm.value.purchaseContractId).then((res) => {
    if (res) {
      ticketList.value = res;
    }
  });
};

/**
 * @description: 处理付款详情
 * @param {Number} id
 */
const getPaymentList = async () => {
  const res = await getSealDetailApi(sealId.value);
  if (res) {
    paymentList.value = res.payApplyInfoRespVos;
  }
};

/**
 * @description: 处理入库
 * @param {Number} id
 */
const getInorderList = async () => {
  // 合同用印到票列表
  await getInorderListApi(requestForm.value.purchaseContractId).then((res) => {
    if (res) {
      inorderList.value = res;
    }
  });
};

/**
 * @description: 获取字典
 */
async function getDicts() {
  // 类型
  await getDictsApi("erp_purchase_contract_type").then((res) => {
    if (res.code === 200) {
      typeList.value = res.data;
    }
  });

  // 发票类型
  await getDictsApi("erp_invoice_type").then((res) => {
    if (res.code === 200) {
      invoiceTypeList.value = res.data;
    }
  });

  // 采购类型
  await getDictsApi("erp_purchase_detail_type").then((res) => {
    if (res.code === 200) {
      purchaseDefaultList.value = res.data;
      purchaseTypeList.value = res.data;
    }
  });

  // 甲方单位
  await getDictsApi("erp_party_units").then((res) => {
    if (res.code === 200) {
      partyUnitsList.value = res.data;
    }
  });

  // 单位列表
  await getDictsApi("material_unit").then((res) => {
    if (res.code === 200) {
      unitList.value = res.data;
    }
  });

  // 解除原因列表
  await getDictsApi("erp_secure_reason").then((res) => {
    if (res.code === 200) {
      relieveList.value = res.data;
    }
  });

  // 采购订单列表
  await getOrderListApi({
    orderCheckStatus: 3,
    purchaseContractId: requestForm.value.purchaseContractId,
  }).then((res) => {
    if (res) {
      orderList.value = res;
      res.forEach((item) => {
        item.value = item.purchaseOrderCode;
      });
    }
  });

  // 供应商列表
  await getSupplierListApi().then((res) => {
    if (res.code === 200) {
      res.rows.forEach((item) => {
        item.value = item.supplierName;
      });
      suppliereList.value = res.rows;
    }
  });

  // 项目列表
  await getProjectListApi({}, {}).then((res) => {
    if (res) {
      projectList.value = res;
    }
  });

  // 原合同列表
  await getRawSealListApi({}, { contractCheckStatus: 3 }).then((res) => {
    if (res) {
      sourceContractList.value = [];
      res.forEach((item) => {
        if (
          item.contractType == 0 ||
          item.contractType == 1 ||
          item.contractType == 3 ||
          item.contractType == 5
        ) {
          item.value = item.purchaseContractName;
          sourceContractList.value.push(item);
        }
      });
      sourceContractList.value = [...sourceContractList.value];
    }
  });

  // 原合同列表
  await getSourceContract().then((res) => {
    if (res) {
      sourceContractList2.value = res;
    }
  });

  // 渠道列表
  await getDictsApi("erp_channel").then((res) => {
    if (res.code === 200) {
      channelList.value = res.data;
    }
  });

  await getUserListApi({}).then((res) => {
    // if (res.code === 200) {
    //   userList.value = res.rows;
    // }
    console.log('经办人列表：')
    console.log(res)
    if (res.length > 0) {
      userList.value = res;
    }
  });
  // 税率列表
  await getDictsApi("default_tax_rate").then((res) => {
    if (res.code === 200) {
      taxRateList.value = res.data;
    }
  });

  // // 销售部门列表
  // await getDeptListApi().then((res) => {
  //   if (res.code === 200) {
  //     deptList.value = res.data;
  //     nextTick(() => {
  //       refSelect.value.focus(); // 聚焦
  //     });
  //   }
  // });
}
/* 选择发票类型 */
const handleTypeChange = (value) => {
  invoiceTypeList.value.forEach((item) => {
    if (item.value == value) {
      contactForm.value.invoiceTypeName = item.label;
    }
  });
};

const openPrompt = (row) => {
  if (row.checkMaterialStatus === 0) {
    ElMessage.warning("请前往采购订单管理，完善物料后再新增合同信息");
  }
};

onMounted(() => {
  getDicts();
  getRequestList();
  // if (props.pageType === "add") {
  //   nextTick(() => {
  //     refSelect.value.focus();
  //   });
  // }
});

defineExpose({
  handleDetailInfo,
});
</script>
<style lang="scss" scoped>
.requestAdd {
  padding: 20px 20px;
  width: 100%;
  height: 100%;
  .request-info {
    padding: 20px 20px 5px 20px;
    background-color: #f0f0f0;
    margin: 10px 0;
  }
  .contact-info {
    padding-top: 20px;
  }

  :deep(.el-table) {
    th.el-table__cell {
      background: #f8f8f8 !important;
    }
  }
  :deep(.el-date-editor.el-input, .el-date-editor.el-input__wrapper) {
    width: 268px !important;
    height: 34px !important;
  }
  .search-input {
    width: 268px;
    height: 34px;
  }
  .image-content {
    width: 100%;
    line-height: 0px;
    overflow: auto;
  }
}
.auto-top {
  width: 100%;
  position: absolute;
  top: 0px;
  display: flex;
  font-weight: bold;
  background-color: #fff;
}
.auto-item {
  width: 125px;
  text-align: left;
  white-space: nowrap; /* 禁止换行 */
  overflow: hidden; /* 隐藏超出部分 */
  text-overflow: ellipsis; /* 使用省略号表示超出部分 */
}
.el-autocomplete .el-autocomplete-suggestion {
  max-height: 200px; /* 设置最大高度 */
  overflow-y: auto; /* 超出高度时显示滚动条 */
}
:deep(.el-form-item--default) {
  margin-bottom: 22px;
}
:deep(.el-form-item--default .el-form-item__error) {
  padding-top: 5px;
}
.disabled-bg {
  background-color: #f5f7fa;
}
</style>
